<%
  # encoding: utf-8
  #
  # Redmine plugin for Document Management System "Features"
  #
  # Copyright © 2011-20 Karel Pičman <karel.picman@kontron.com>
  #
  # This program is free software; you can redistribute it and/or
  # modify it under the terms of the GNU General Public License
  # as published by the Free Software Foundation; either version 2
  # of the License, or (at your option) any later version.
  #
  # This program is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public License
  # along with this program; if not, write to the Free Software
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
%>

<ul>
  <li>
    <%= context_menu_link l(:button_download), entries_operations_dmsf_path(:id => @project, :folder_id => @folder,
      :ids => params[:ids], :download_entries => true), :method => :post, :class => 'icon icon-download',
      :id => 'dmsf-cm-download', :disabled => @disabled %>
  </li>
  <li>
    <%= context_menu_link l(:field_mail), entries_operations_dmsf_path(:id => @project, :folder_id => @folder,
      :ids => params[:ids], :email_entries => true), :method => :post, :class => 'icon icon-email',
      :disabled => @disabled || (!User.current.allowed_to?(:email_documents, @project)) %>
  </li>
  <li>
    <%= context_menu_link l(:button_delete), entries_operations_dmsf_path(:id => @project, :folder_id => @folder,
      :ids => params[:ids], :delete_entries => true), :method => :post, :class => 'icon icon-del',
      :data => { :confirm => l(:text_are_you_sure) }, :id => 'dmsf-cm-delete',
      :disabled => @disabled || ((!User.current.allowed_to?(:folder_manipulation, @project)) &&
          (!User.current.allowed_to?(:file_delete, @project)))%>
  </li>
  <% if @file %>
    <li>
      <% if @file.last_revision && @file.last_revision.protocol %>
        <% url = "#{@file.last_revision.protocol}:ofe|u|#{Setting.protocol.strip}://#{Setting.host_name.strip}/dmsf/webdav/#{Addressable::URI.escape(RedmineDmsf::Webdav::ProjectResource.create_project_name(@file.project))}/" %>
        <% if @file.dmsf_folder %>
          <% url << "#{@file.dmsf_folder.dmsf_path_str}/" %>
        <% end %>
        <% url << @file.name %>
      <% end %>
      <%= context_menu_link l(:button_edit), url, :class => 'icon icon-edit', :disabled => url.blank? %>
    </li>
  <% end %>
</ul>

<%= late_javascript_tag do %>
  $('#dmsf-cm-download').click(function (event) {
    contextMenuHide();
  });

  $('#dmsf-cm-delete').click(function (event) {
    contextMenuHide();
  });
<% end %>
